from selenium.webdriver.common.by import By
from time import sleep
class LoginPage():
    def __init__(self,driver):
        self.driver = driver

    def login(self, username, password,money, time):
        # 输入用户名
        self.driver.find_element(By.ID, "username").send_keys(username)
        # 输入密码
        self.driver.find_element(By.ID, "password").send_keys(password)
        # 点击登录
        self.driver.find_element(By.ID, "login_btn").click()
        sleep(1)
        #点击金融工具
        self.driver.find_element(By.XPATH,"//*[@id='leftbaraside']/div[2]/nav/ul/li[3]/a").click()
        #点击安全网贷
        self.driver.find_element(By.XPATH, "/html/body/div[1]/div/aside/div[2]/nav/ul/li[3]/ul/li[2]/a").click()
        #输入金额
        self.driver.find_element(By.XPATH, "/html/body/div[1]/div/main/div/div/div/div/div[2]/div/form/div[1]/input").send_keys(money)
        #输入时间
        self.driver.find_element(By.XPATH, "/html/body/div[1]/div/main/div/div/div/div/div[2]/div/form/div[3]/input").send_keys(time)
        #点击贷款
        self.driver.find_element(By.XPATH, "/html/body/div[1]/div/main/div/div/div/div/div[2]/div/form/div[4]/button").click()
        sleep(1)
        #点击确认
        self.driver.find_element(By.XPATH,"/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button[1]").click()
        sleep(0.5)
        # 获取值
        result=self.driver.find_element(By.XPATH,"/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[3]/div/div").text


        return result

    def login3(self, username, password,money, time):
        # 输入用户名
        self.driver.find_element(By.ID, "username").send_keys(username)
        # 输入密码
        self.driver.find_element(By.ID, "password").send_keys(password)
        # 点击登录
        self.driver.find_element(By.ID, "login_btn").click()
        sleep(1)
        #点击金融工具
        self.driver.find_element(By.XPATH,"//*[@id='leftbaraside']/div[2]/nav/ul/li[3]/a").click()
        #点击安全网贷
        self.driver.find_element(By.XPATH, "/html/body/div[1]/div/aside/div[2]/nav/ul/li[3]/ul/li[2]/a").click()
        #输入金额
        self.driver.find_element(By.XPATH, "/html/body/div[1]/div/main/div/div/div/div/div[2]/div/form/div[1]/input").send_keys(money)
        #输入时间
        self.driver.find_element(By.XPATH, "/html/body/div[1]/div/main/div/div/div/div/div[2]/div/form/div[3]/input").send_keys(time)
        #点击贷款
        self.driver.find_element(By.XPATH, "/html/body/div[1]/div/main/div/div/div/div/div[2]/div/form/div[4]/button").click()


        # 获取值
        result=self.driver.find_element(By.XPATH,"/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[3]/span").text


        return result

    def login2_1(self, username, password,money, time):
        # 输入用户名
        self.driver.find_element(By.ID, "username").send_keys(username)
        # 输入密码
        self.driver.find_element(By.ID, "password").send_keys(password)
        # 点击登录
        self.driver.find_element(By.ID, "login_btn").click()
        sleep(1)
        #点击金融工具
        self.driver.find_element(By.XPATH,"//*[@id='leftbaraside']/div[2]/nav/ul/li[3]/a").click()
        #点击安全网贷
        self.driver.find_element(By.XPATH, "/html/body/div[1]/div/aside/div[2]/nav/ul/li[3]/ul/li[2]/a").click()
        #输入金额
        self.driver.find_element(By.XPATH, "/html/body/div[1]/div/main/div/div/div/div/div[2]/div/form/div[1]/input").send_keys(money)
        #输入时间
        self.driver.find_element(By.XPATH, "/html/body/div[1]/div/main/div/div/div/div/div[2]/div/form/div[3]/input").send_keys(time)
        #点击贷款
        self.driver.find_element(By.XPATH, "/html/body/div[1]/div/main/div/div/div/div/div[2]/div/form/div[4]/button").click()
        sleep(1)
        #点击确认
        self.driver.find_element(By.XPATH,"/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button[1]").click()
        sleep(2)
        #点击个人中心
        self.driver.find_element(By.XPATH,"/html/body/div/div/aside/div[2]/nav/ul/li[4]/a").click()
        # 点击银行卡管理
        self.driver.find_element(By.XPATH,"/html/body/div/div/aside/div[2]/nav/ul/li[4]/ul/li[3]/a").click()
        # 获取值
        result=self.driver.find_element(By.XPATH,"/html/body/div/div/main/div/div/div[2]/div/div/div[2]/h4[2]").text

        return result

    def login2_2(self, username='admin', password="123456"):
       # 输入用户名
        self.driver.find_element(By.ID, "username").send_keys(username)
        # 输入密码
        self.driver.find_element(By.ID, "password").send_keys(password)
        # 点击登录
        self.driver.find_element(By.ID, "login_btn").click()
        sleep(1)
        #点击网贷管理
        self.driver.find_element(By.XPATH,"/html/body/div/div/aside/div[2]/nav/ul/li[5]/a").click()
        #点击网贷审核
        self.driver.find_element(By.XPATH, "/html/body/div/div/aside/div[2]/nav/ul/li[5]/ul/li[1]/a").click()
        #点击通过
        self.driver.find_element(By.XPATH, "/html/body/div/div/main/div/div/div/div/div[2]/div/table/tbody/tr[1]/td[7]/button[1]").click()

       # 点击同意
        self.driver.find_element(By.XPATH,"/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button[1]").click()
        sleep(2)
    def login2_3(self, username, password):
        # 输入用户名
        self.driver.find_element(By.ID, "username").send_keys(username)
        # 输入密码
        self.driver.find_element(By.ID, "password").send_keys(password)
        # 点击登录
        self.driver.find_element(By.ID, "login_btn").click()
        sleep(1)
        #点击个人中心
        self.driver.find_element(By.XPATH,"/html/body/div/div/aside/div[2]/nav/ul/li[4]/a").click()
        # 点击银行卡管理
        self.driver.find_element(By.XPATH,"/html/body/div/div/aside/div[2]/nav/ul/li[4]/ul/li[3]/a").click()
        # 获取值
        result=self.driver.find_element(By.XPATH,"/html/body/div/div/main/div/div/div[2]/div/div/div[2]/h4[2]").text



        return result